zxt.core.ValidatorType = {
	REGEX : "REGEX ERROR",
	REQUIRED : "REQUIRED ERROR",
	FORMAT : "FORMAT ERROR",
	CARD : "CARD ERROR",
	LIST : "CONTENT NOT IN LIST",
	UNDEFINED : "WIDGETS UNDEFINED",
	DATE : "DATE ERROR"
};

zxt.core.Validator = function() {	
	
};	

zxt.defineClazz(zxt.core.Validator);

zxt.core.Validator.prototype.validate = function( str ){
	
};	

/**
 * 验证对象构造函数
 * @class 校验对象 该对象提供基本的校验方法 
 */
zxt.core.ValidatorElement = function() {	
	this._nullable = true;
	this._minByte = 0;
	this._maxByte = Number.MAX_VALUE;	
	this._regex = null;
	this._prompt = "";
};

zxt.defineClazz(zxt.core.ValidatorElement, zxt.core.Validator);

zxt.core.ValidatorElement.prototype.nullable = function(v){
  if (v === undefined) {	return this._nullable;	};
  this._nullable = v;
};

zxt.core.ValidatorElement.prototype.minByte = function(v){
  if (v === undefined) {	return this._minByte;	};
  this._minByte = v;
};

zxt.core.ValidatorElement.prototype.maxByte = function(v){
  if (v === undefined) {	return this._maxByte;	};
  this._maxByte = v;
};

zxt.core.ValidatorElement.prototype.regex = function(v){
  if (v === undefined) {	return this._regex;	};
  this._regex = v;
};

zxt.core.ValidatorElement.prototype.prompt = function(v){
  if (v === undefined) {	return this._prompt;	};
  this._prompt = v;
};

zxt.core.ValidatorElement.prototype.validate = function( str ){
	var errReturn = new Array();

	if( this._nullable && str.trim() == "" ){
		return errReturn;
	};
	
	if( !this._nullable && str.trim() == "" )	{
		errReturn.push("数据不能为空");
		return errReturn;		
	};
	
	var byteLen = zxt.util.getByteLength( str );
	if( byteLen > this._maxByte || byteLen < this._minByte )
	{
		var errt = " 数据至少" + this._minByte + "位至多" + this._maxByte + "位";
		errReturn.push(errt);
	};
	
	var r = this.regex();
	if( r != null && !r.test(str)){
		errReturn.push(this._prompt);
	};
	
	return errReturn;
	
};


zxt.core.ValidatorChain = function() {	
	this._validators = new Array();
};

zxt.defineClazz(zxt.core.ValidatorChain, zxt.core.Validator);
	
zxt.core.ValidatorChain.prototype.chain = function(vd){
	this._validators.push(vd);
	return this;
};

zxt.core.ValidatorChain.prototype.validate = function( str ){
	var errs = new Array();
	for( var i=0; i<this._validators.length; i++ ){
		var _err = this._validators[i].validate(str);
		for( var j=0; j<_err.length; j++ ){
			errs.push(_err[j]);
		};			
	};
	return errs;
};
	

zxt.core.ValidatorManager = {
	validators : {},
	register : function(type, reg, errormsg){
		var vd = new zxt.core.ValidatorElement();
		vd.regex(reg);
		vd.prompt(errormsg);
		this.validators[type] = vd;
	},
	getValidator : function(type){
		return this.validators[type];
	}	
};

zxt.core.ValidatorManager.register( "email", /^([_a-z0-9]|[\.]|[\-])+@(([_a-z0-9]|[\-])+\.)+[a-z0-9]+$/i, "非法email地址" );
zxt.core.ValidatorManager.register( "mobile_phone", /^1[35](\d{9})$/, "非法手机号码" );
zxt.core.ValidatorManager.register( "postcode", /^(\d{6})$/, "非法邮政编码" );
zxt.core.ValidatorManager.register( "phone_with_area_code", /^[0-9]{3,4}-[0-9]{3,11}(-[0-9]{0,}){0,1}$/, "非法电话号码");
zxt.core.ValidatorManager.register( "phone_without_area_code", /^[1-9]{1}[0-9]{2,10}$/, "非法电话号码" );
zxt.core.ValidatorManager.register( "integer", /^[-]{0,1}[1-9]+[0-9]{0,}$|^[0]{1,1}$/, "必须输入整数" );
zxt.core.ValidatorManager.register( "positive_integer", /^[1-9]+[0-9]{0,}$/, "必须输入正整数" );
zxt.core.ValidatorManager.register( "nonnegative_integer", /^[1-9]+[0-9]{0,}$|^[0]{1,1}$/, "必须输入非负整数");
zxt.core.ValidatorManager.register( "negative_integer", /^-[1-9]+[0-9]{0,}$/, "必须输入负整数");
zxt.core.ValidatorManager.register( "http_url", /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i, "非法http地址" );
zxt.core.ValidatorManager.register( "number", /^[-]{0,1}[1-9]+[0-9]{0,}$|^[-]{0,1}[1-9]+[0-9]{0,}[\.][0-9]+$|^[-]{0,1}[0]{0,1}[\.][0-9]+$|^[0]{1,1}$/, "必须输入数字" ); 
zxt.core.ValidatorManager.register( "nonnegative_number", /^[1-9]+[0-9]{0,}$|^[1-9]+[0-9]{0,}[\.][0-9]+$|^[0]{0,1}[\.][0-9]+$|^[0]{1,1}$/, "必须输入非负数字" ); 
zxt.core.ValidatorManager.register( "positive_number", /^[1-9]+[0-9]{0,}$|^[1-9]+[0-9]{0,}[\.][0-9]+$|^[0]{0,1}[\.][0-9]+$/, "必须输入正数字" ); 
zxt.core.ValidatorManager.register( "decimal", /^[-]{0,1}[0]{0,1}[\.][0-9]+$/, "必须输入小数" );
zxt.core.ValidatorManager.register( "label", /^[a-z]{1}([a-z0-9]|[_])+$/i, "非法的标签名" );
zxt.core.ValidatorManager.register( "string", /^([a-z0-9]|[_])+$/i, "非法的英文字符串" );
zxt.core.ValidatorManager.register( "chinese_string", /^([a-z0-9]|[_]|[\u4E00-\u9FA5])+$/i, "非法的中文字符串" );
zxt.core.ValidatorManager.register( "not_chinese_string", /^[^\u4E00-\u9FA5]*$/i, "包含非法的中文字符串" );
zxt.core.ValidatorManager.register( "ip_address", /^([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-4][0-9]|25[0-5])([\.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-4][0-9]|25[0-5])){3}$/, "非法的IP地址" );
zxt.core.ValidatorManager.register( "text", /^([\w]|[\W])*$/i, "非法的字符串" );
zxt.core.ValidatorManager.register( "mac", /^[0-9a-f]{2}([:][0-9a-f]{2}){5}$|^[0-9a-f]{2}([\-][0-9a-f]{2}){5}$/i, "非法的MAC地址" );	